/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-1-15 下午6:46 Created by dwzhang
 */
package com.jade.modules.cms;

import java.util.Date;
import java.util.Map;
import java.util.Set;
import javax.persistence.*;

/**
 * 内容对象定义。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-1-15 下午6:46
 */
//@Entity
//@Table (name = "MODULE_CMS_CONTENT")
public class Content extends CmsEntity
{
    //新建内容
    public static final int STATUS_CREATED = 0;
    //提交待审核
    public static final int STATUS_SUBMITTED = 1;
    //第一次审核通过的状态
    public static final int STATUS_AUDITED = 3;
    //已发布
    public static final int STATUS_PUBLISHED = 8;
    //第一次审核拒绝的状态
    public static final int STATUS_REFUSED = 13;
    //发布撤销状态
    public static final int STATUS_WITHDRAWED = 18;

    @Id
    @GeneratedValue (generator = "MODULE_SEQ_CMS_CONTENT")
    @SequenceGenerator (name = "MODULE_SEQ_CMS_CONTENT", initialValue = 100, sequenceName = "MODULE_SEQ_CMS_CONTENT")
    private long id;
    //内容类型，例如新闻、图集、通知等等
    @Column (name = "type", nullable = false, updatable = false, length = 16)
    private String type;
    //内容栏目
    @Column (name = "category_id")
    private long categoryId;
    //内容所属专题,专题也是一个分类
    @Column (name = "topic_id")
    private long topicId;
    //简单标题
    @Column (name = "title", nullable = false, length = 128)
    private String title;
    //内容详情
    @Lob
    @Column (name = "details")
    private String details;
    //内容作者
    @Column (name = "author", length = 32)
    private String author;
    //内容来源
    @Column (name = "source", length = 32)
    private String source;
    //外部url
    @Column (name = "link_url", length = 64)
    private String linkUrl;
    //是否焦点
    private boolean focus;
    //是否推荐
    @Column (name = "recommend")
    private boolean recommend;
    //内容模版
    @Column (name = "template_id")
    private long templateId;
    //内容生成的html文件
    @Column (name = "html_file", length = 64)
    private String htmlFile;
    //发布日期
    @Column (name = "publish_date")
    private Date publishDate;
    //有效期开始时间
    @Column (name = "valid_begin_date")
    private Date validBeginDate;
    //有效器结束时间
    @Column (name = "valid_end_date")
    private Date validEndDate;
    //内容属性
    @ElementCollection (fetch = FetchType.EAGER)
    @MapKeyColumn (name = "name")
    @Column (name = "value")
    @CollectionTable (name = "MODULE_CMS_CONTENT_PROPS", joinColumns = @JoinColumn (name = "content_id"))
    private Map<String, String> properties;
    //内容标签
    @ElementCollection (targetClass = String.class, fetch = FetchType.EAGER)
    @CollectionTable (name = "MODULE_CMS_CONTENT_TAGS", joinColumns = @JoinColumn (name = "content_id"))
    @Column (name = "tag")
    private Set<String> tags;

    @Transient
    private ContentCount count;

    public Content()
    {
        setStatus(STATUS_CREATED);
    }

    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public long getCategoryId()
    {
        return categoryId;
    }

    public void setCategoryId(long categoryId)
    {
        this.categoryId = categoryId;
    }

    public long getTopicId()
    {
        return topicId;
    }

    public void setTopicId(long topicId)
    {
        this.topicId = topicId;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }

    public String getDetails()
    {
        return details;
    }

    public void setDetails(String details)
    {
        this.details = details;
    }

    public String getAuthor()
    {
        return author;
    }

    public void setAuthor(String author)
    {
        this.author = author;
    }

    public String getSource()
    {
        return source;
    }

    public void setSource(String source)
    {
        this.source = source;
    }

    public String getLinkUrl()
    {
        return linkUrl;
    }

    public void setLinkUrl(String linkUrl)
    {
        this.linkUrl = linkUrl;
    }

    public boolean isFocus()
    {
        return focus;
    }

    public void setFocus(boolean focus)
    {
        this.focus = focus;
    }

    public boolean isRecommend()
    {
        return recommend;
    }

    public void setRecommend(boolean recommend)
    {
        this.recommend = recommend;
    }

    public long getTemplateId()
    {
        return templateId;
    }

    public void setTemplateId(long templateId)
    {
        this.templateId = templateId;
    }

    public String getHtmlFile()
    {
        return htmlFile;
    }

    public void setHtmlFile(String htmlFile)
    {
        this.htmlFile = htmlFile;
    }

    public Date getValidBeginDate()
    {
        return validBeginDate;
    }

    public void setValidBeginDate(Date validBeginDate)
    {
        this.validBeginDate = validBeginDate;
    }

    public Date getValidEndDate()
    {
        return validEndDate;
    }

    public void setValidEndDate(Date validEndDate)
    {
        this.validEndDate = validEndDate;
    }

    public Map<String, String> getProperties()
    {
        return properties;
    }

    public void setProperties(Map<String, String> properties)
    {
        this.properties = properties;
    }

    public Set<String> getTags()
    {
        return tags;
    }

    public void setTags(Set<String> tags)
    {
        this.tags = tags;
    }

    public Date getPublishDate()
    {
        return publishDate;
    }

    public void setPublishDate(Date publishDate)
    {
        this.publishDate = publishDate;
    }

    public ContentCount getCount()
    {
        return count;
    }

    public void setCount(ContentCount count)
    {
        this.count = count;
    }
}
